<!-- 消防隐患-详情 -->
<template>
	<view class="page">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block style="color: ##777777;font-size: 32rpx;" slot="content">隐患详情</block>
		</cu-custom>
		<view class="content" style="background-color: #fff;">
			<ul>
				<li v-if="dangerForm.abnormalPic">
					<text class="list-info">隐患图片：</text>
					<image :src="dangerForm.abnormalPic"></image>
				</li>
				<li>
					<text class="list-info">隐患名称：</text>
					<text class="list-title">{{dangerForm.name || '暂无'}}</text>
				</li>
				<li>
					<text class="list-info">执行时间：</text>
					<text class="list-title">{{dangerForm.executeTime | dateFormat}} </text>
				</li>
				<li>
					<text class="list-info">隐患描述：</text>
					<text class="list-title">{{dangerForm.remark || '暂无'}} </text>
				</li>
				<li>
					<text class="list-info">所属企业：</text>
					<text class="list-title">{{dangerForm.enterpriseName || '暂无'}} </text>
				</li>
				<li>
					<text class="list-info">所属区域：</text>
					<text class="list-title">{{dangerForm.regionName || '暂无'}} </text>
				</li>
				<li>
					<text class="list-info">隐患地点：</text>
					<text class="list-title">{{dangerForm.address || '暂无'}} </text>
				</li>
				<li v-if="dangerForm.reportPersonName">
					<text class="list-info">上报人：</text>
					<text class="list-title">{{dangerForm.reportPersonName || '暂无'}} </text>
				</li>
				<li v-if="dangerForm.reportPersonTel">
					<text class="list-info">上报人电话：</text>
					<text class="list-title">{{dangerForm.reportPersonTel || '暂无'}} </text>
				</li>
				<li v-if="dangerForm.reportTime">
					<text class="list-info">上报时间：</text>
					<text class="list-title">{{dangerForm.reportTime | dateFormat}} </text>
				</li>
				<li>
					<text class="list-info">当前状态：</text>
					<text class="list-title">{{dangerForm.statusStr || '暂无'}} </text>
				</li>
				<li>
					<text class="list-info">整改期限：</text>
					<text class="list-title">{{dangerForm.deadline | dateFormat}} </text>
				</li>
				<li v-if="dangerForm.status === 12">
					<text class="list-info">申请整改时间：</text>
					<text class="list-title">{{dangerForm.examineTime | dateFormat}} </text>
				</li>
				<li v-if="dangerForm.status === 4">
					<text class="list-info">完成时间：</text>
					<text class="list-title">{{dangerForm.completeTime | dateFormat}} </text>
				</li>
				<li v-if="dangerForm.status === 4">
					<text class="list-info">完成图片：</text>
					<image :src="dangerForm.completeUrl"></image>
				</li>
				<li v-if="dangerForm.status === 6">
					<text class="list-info">误报图片：</text>
					<image :src="dangerForm.misreportUrl"></image>
				</li>
				<li v-if="dangerForm.status === 6">
					<text class="list-info">误报描述：</text>
					<text class="list-title">{{dangerForm.misreportDesc || '暂无'}} </text>
				</li>
			</ul>
		</view>

		<!-- 处理按钮 -->
		<view class="flex btns-group">
			<button class="my-btn-grpup" v-if="dangerForm.status===6" @click="mistakePassClick()">同意隐患误报</button>
			<button class="my-btn-grpup" v-if="dangerForm.status===6" @click="mistakeUnPassClick()">不同意隐患误报</button>
			<button class="my-btn-grpup" v-if="dangerForm.status===12" @click="agreeExamineTime()">同意整改时间</button>
			<button class="my-btn-grpup" v-if="dangerForm.status===12" @click="checkExamineTime()">审核整改时间</button>
			<button class="my-btn-grpup" v-if="dangerForm.status===9" @click="checkExamineTime()">延期审核</button>
			<button class="my-btn-grpup" v-if="dangerForm.status===10" @click="qyapproved()">通过审核</button>
			<button class="my-btn-grpup" v-if="dangerForm.status===10" @click="qyunapproved()">审核不通过</button>
		</view>

		<!-- 弹出层 -->
		<u-popup :show="checkTimeShow" closeOnClickOverlay @close="checkTimeShow = false">
			<u-form labelPosition="left" :model="model1" ref="form1">
				<u-form-item label="整改期限" prop="fireAuditTime" borderBottom
					@click="showDateTime = true" ref="item1">
					<u-input v-model="model1.fireAuditTime" disabled disabledColor="#ffffff" placeholder="请指定整改期限"
						border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item label="审核意见" prop="fireAuditOpinion" borderBottom>
					<u-input v-model="model1.fireAuditOpinion" placeholder="请输入审核意见"></u-input>
				</u-form-item>
			</u-form>
			<u-datetime-picker :show="showDateTime" v-model="timeValue" mode="datetime" @confirm="onConfirm()" @cancel="showDateTime=false">
			</u-datetime-picker>
			<view class="flex btns-group">
				<button class="my-btn-grpup" @click="checkTimeSubmit()">确认</button>
				<button class="my-btn-grpup" @click="checkTimeShow=false">取消</button>
			</view>
		</u-popup>
		<u-toast ref="uToast"></u-toast>
		<message />
	</view>
</template>

<script>
	import * as constants from '@/common/config.js'
	import {
		formatDate,formatDates
	} from '@/common/formatDate.js'
	export default {
		data() {
			return {
				dangerForm: {},
				ucId: '',
				checkTimeShow: false,
				model1: {
					ucId: null,
					fireAuditTime: null,
					fireAuditOpinion: null
				},
				rules1: {
					fireAuditTime: [{
						required: true,
						message: '请指定整改期限',
						trigger: ['change', 'blur'],
					}],
					fireAuditOpinion: [{
						required: true,
						message: '请输入审核意见',
						trigger: ['change', 'blur'],
					}]
				},
				showDateTime: false,
				timeValue:Number(new Date())
			}
		},
		onLoad(option) {
			this.ucId = option.ucId
			this.xq()
		},
		methods: {
			xq() {
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/inHiddenDanger/getInHiddenDanger',
					data: {
						"ucId": that.ucId
					}
				}).then(function(res) {
					that.dangerForm = res.data.data
				}).catch(function(e) {})
			},
			// 同意隐患误报
			mistakePassClick() {
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/inHiddenDanger/mistakePass',
					data: {
						"ucId": that.ucId
					}
				}).then(function(res) {
					that.$refs.uToast.show({
						message: "审核成功",
						type: 'success',
						complete() {
							uni.navigateBack({
								delta: 1
							})
						}
					})
				}).catch(function(e) {})
			},
			// 不同意隐患误报
			mistakeUnPassClick() {
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/inHiddenDanger/mistakeUnPass',
					data: {
						"ucId": that.ucId
					}
				}).then(function(res) {
					that.$refs.uToast.show({
						message: "审核成功",
						type: 'success',
						complete() {
							uni.navigateBack({
								delta: 1
							})
						}
					})
				}).catch(function(e) {})
			},
			// 同意整改时间
			agreeExamineTime() {
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/inHiddenDanger/fireReviewRectificationTime',
					data: {
						"ucId": that.ucId,
						"fireAuditTime": formatDates(that.dangerForm.examineTime,"yyyy-MM-dd hh:mm:ss"),
						"fireAuditOpinion": '同意整改时间'
					}
				}).then(function(res) {
					that.$refs.uToast.show({
						message: "审核成功",
						type: 'success',
						complete() {
							uni.navigateBack({
								delta: 1
							})
						}
					})
				}).catch(function(e) {})
			},
			// 审核整改时间
			checkExamineTime() {
				this.model1.ucId = null,
				this.model1.fireAuditTime = null,
				this.model1.fireAuditOpinion = null,
				this.checkTimeShow = true
			},
			// 审核整改时间提交
			checkTimeSubmit() {
				this.$refs.form1.validate().then(res => {
					this.model1.ucId = this.ucId
					let url = ''
					if (this.dangerForm.status === 12) {
						url = 'wx/inHiddenDanger/fireReviewRectificationTime'
					} else if (this.dangerForm.status === 9) {
						url = 'wx/inHiddenDanger/hiddenDangerContinueToRectify'
					}
					let that = this
					// 请求数据
					let app = getApp()
					app.globalData.request({
						url: url,
						data: that.model1
					}).then(function(res) {
						that.$refs.uToast.show({
							message: "审核成功",
							type: 'success',
							complete() {
								uni.navigateBack({
									delta: 1
								})
							}
						})
					}).catch(function(e) {})
				}).catch(errors => {})
			},
			// 通过审核
			qyapproved() {
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/inHiddenDanger/approved',
					data: {
						"ucId": that.ucId
					}
				}).then(function(res) {
					that.$refs.uToast.show({
						message: "审核成功",
						type: 'success',
						complete() {
							uni.navigateBack({
								delta: 1
							})
						}
					})
				}).catch(function(e) {})
			},
			// 审核不通过
			qyunapproved() {
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/inHiddenDanger/unapproved',
					data: {
						"ucId": that.ucId
					}
				}).then(function(res) {
					that.$refs.uToast.show({
						message: "审核成功",
						type: 'success',
						complete() {
							uni.navigateBack({
								delta: 1
							})
						}
					})
				}).catch(function(e) {})
			},
			onConfirm(e) {
				this.model1.fireAuditTime = formatDate(e.value)
				this.$refs.form1.validateField('fireAuditTime')
				this.showDateTime = false
			}
		},
		onReady() {
			this.$refs.form1.setRules(this.rules1);
		}
	}
</script>

<style scoped>
</style>
